<?php
/**
 * Netflix_Title Class
 *
 * @author Armando Padilla, armando_padilla_81@yahoo.com
 * @package Zend_Service_Netflix
 * 
 */
class Netflix_Title {

	/**
	 * Title Id
	 *
	 * @var unknown_type
	 */
	public $id;
	
	/**
	 * Full Title
	 *
	 * @var unknown_type
	 */
	public $title;
	
	/**
	 * Short Title.
	 *
	 * @var unknown_type
	 */
	public $titleShort;
	
	/**
	 * API URL Ref.
	 *
	 * @var unknown_type
	 */
	public $synops;

	
	/**
	 * URL to location of small box art.
	 *
	 * @var unknown_type
	 */
	public $boxArtSmall;
	
	/**
	 * URL to location of medium box art.
	 *
	 * @var unknown_type
	 */
	public $boxArtMedium;
	
	/**
	 * URL to location of large box art.
	 *
	 * @var unknown_type
	 */
	public $boxArtLarge;
	
	/**
	 * Release Year.
	 *
	 * @var unknown_type
	 */
	public $releaseYear;
	
	/**
	 * MPAA Rating.
	 *
	 * @var unknown_type
	 */
	public $mpaaRating;
	
	/**
	 * Genre.
	 *
	 * @var unknown_type
	 */
	public $genres = array();
	
	/**
	 * Average Rating.
	 *
	 * @var unknown_type
	 */
	public $avarageRating;
	
	/**
	 * TV Rating.
	 *
	 * @var unknown_type
	 */
	public $tvRating = array();
	
	/**
	 * API URL.
	 *
	 * @var unknown_type
	 */
	public $castURL;
	
	/**
	 * API URL.
	 *
	 * @var unknown_type
	 */
	public $directorURL;
	
	
	/**
	 * Length.
	 *
	 * @var unknown_type
	 */
	public $length;
	
	/**
	 * API URL.
	 *
	 * @var unknown_type
	 */
	public $awardsURL;
	
	
	public $bonusMaterial;
	public $hasBonusMaterial;
	
	
	public $deliveryFormat;
	
	/**
	 * API URL.
	 *
	 * @var unknown_type
	 */
	public $screenFormatsURL;
	
	/**
	 * API Ref URL.
	 *
	 * @var unknown_type
	 */
	public $formatAvailability;
	
	/**
	 * API URL.
	 *
	 * @var unknown_type
	 */
	public $languageAndSoundURL;
	
	
	/**
	 * URL of movie on Netflix.
	 *
	 * @var unknown_type
	 */
	public $netflixUrl; 
	
	
	/**
	 * Official Web Site URL.
	 *
	 * @var unknown_type
	 */
	public $officialTitleUrl;
	
	/**
	 * API URL.
	 *
	 * @var unknown_type
	 */
	public $similarTitles;
	
	/**
	 * API Ref URL.
	 *
	 * @var unknown_type
	 */
	public $series;
	
	/**
	 * API Ref URL. (TV)
	 *
	 * @var unknown_type
	 */
	public $episodesURL;
	
	/**
	 * API Ref URL (TV)
	 *
	 * @var unknown_type
	 */
	public $seasonsURL;
	
	public $links;
	public $inQueue;
	
  
	public function __construct(){}
	
	
	/**
	 * Load Data from XML.
	 *
	 * @param unknown_type $simpleXmlObject
	 */
	public function loadXML($simpleXmlObject){
		
		
		$this->id            = (string)$simpleXmlObject->id;
		$this->title         = (string)$simpleXmlObject->title['regular'];
		$this->titleShort    = (string)$simpleXmlObject->title['short'];
		$this->boxArtSmall   = (string)$simpleXmlObject->box_art['small'];
		$this->boxArtMedium  = (string)$simpleXmlObject->box_art['medium'];
		$this->boxArtLarge   = (string)$simpleXmlObject->box_art['large'];
		$this->releaseYear   = (string)$simpleXmlObject->release_year;
		$this->avarageRating = (string)$simpleXmlObject->average_rating;
		
		foreach($simpleXmlObject->link as $elem){
		
			$title = (string)$elem['title'];
			$href  = (string)$elem['href'];
			$rel   = (string)$elem['rel'];
			
			//Synopsis - need to call API to get full synops
			if($title == "synopsis"){
				$this->synops = $href;
			}
			
			//Awards
			if($title == "awards"){
				$this->awardsURL = $href;
			}
			
			
			//Cast - need to call API to get full Cast Object
			if($title == "cast"){
				$this->castURL = $href;
			}
			
			//Directors - need to call API to get full Directors Object
			if($title == "directors"){
				$this->directorURL = $href;
			}
						
			//Formats - need to call API to get full Formats Object
			if($title == "formats"){
				$this->formats = $href;
			}
			
			//Screen Formats
			if($title == "screen formats"){
				$this->screenFormatsURL = $href;
			}
			
			//Languages & Audio
			if($title == "languages and audio"){
				$this->languageAndSoundURL = $href;
			}
			
			//Similar Titles
			if($title == "similars"){
				$this->similarTitles = $href;
			}
			
			//Netflix Title Web Page
			if($title == "web page" && $rel == "alternate"){
				$this->netflixUrl = $href;
			}			
			
			//Official Web Site
			if($title == "official webpage"){
				$this->officialTitleUrl = $href;
			}
			
			
			//Episodes
			if($title == "episodes"){
				$this->episodesURL = $href;
			}
			
			
			//Seasons
			if($title == "seasons"){
				$this->seasonsURL = $href;
			}
			
					
		}
		
		
		foreach($simpleXmlObject->category as $elem){
			
			$value  = (string)$elem['label'];
			$scheme = (string)$elem['scheme'];
			
			//mpaa rating
			if(strpos($scheme, 'mpaa_ratings')){
				$this->mpaaRating = $value;
			}
			
			//genres
			if(strpos($scheme, 'genres')){
				array_push($this->genres, $value);
			}
			
			//tv ratings
			if(strpos($scheme, 'tv_ratings')){
				array_push($this->tvRating, $value);
			}
			
		}
	
		
	}
	
	
}	
?>